package com.tvein.sanguo.controller.Game.user
{
	//flash
	//pureMVC
	import org.puremvc.as3.multicore.interfaces.ICommand;
	import org.puremvc.as3.multicore.interfaces.INotification;
	import org.puremvc.as3.multicore.utilities.fabrication.patterns.command.SimpleFabricationCommand;
	//custom
	import com.tvein.sanguo.common.CommonConstants;
	import com.tvein.sanguo.model.RoleProxy;
//
	public class RoleStatus extends SimpleFabricationCommand implements ICommand
	{
		private var roleData:RoleProxy;
		
		override public function execute(notification:INotification) : void
		{
			roleData = facade.retrieveProxy(RoleProxy.NAME) as RoleProxy;
			
			var i:int, j:int;
			
			var strID:String;
			var strName:String;
			var strState:String;
			
			//Goods
			var strCarry:String;
			var strStore:String;
			var strUnit:String;
			
			//Skill
			var strRank:String;
			var strExp:String;
			
			//Mission
			var strDetail:String;
			
			switch(notification.getBody()[1][0])
			{
				case "Detail":
					for (i = 0; i < notification.getBody()[1][1][0].length; i++)
					{
						roleData.roleDetail = {"name":notification.getBody()[1][1][0][i].name, "value":notification.getBody()[1][1][0][i].value};
						
						switch(notification.getBody()[1][1][0][i].name)
						{
							case "Role_ID":
								routeNotification(CommonConstants.MODULE_INVOKE, ["-init", ["roleID", notification.getBody()[1][1][0][i].value]], null, "*");
								break;	
							case "ImageID":
								routeNotification(CommonConstants.MODULE_INVOKE, ["-head", notification.getBody()[1][1][0][i].value], null, CommonConstants.MODULE_CHARACTER + "/*");
								break;
							case "StaminaNum":
								routeNotification(CommonConstants.MODULE_INVOKE, ["-stamina", notification.getBody()[1][1][0][i].value], null, CommonConstants.MODULE_CHARACTER + "/*");
								break;
							case "EnergyNum":
								routeNotification(CommonConstants.MODULE_INVOKE, ["-energy", notification.getBody()[1][1][0][i].value], null, CommonConstants.MODULE_CHARACTER + "/*");
								break;
						}
					}
					
					break;
				case "Goods":
					for (i = 0; i < notification.getBody()[1][1].length; i++)
					{						
						for (j = 0; j < notification.getBody()[1][1][i].length; j++)
						{
							switch(notification.getBody()[1][1][i][j].name)
							{
								case "Goods_ID":
									strID = notification.getBody()[1][1][i][j].value;
									break;
								case "Name":
									strName = notification.getBody()[1][1][i][j].value;
									break;
								case "Carry":
									strCarry = notification.getBody()[1][1][i][j].value;
									break;
								case "Store":
									strStore = notification.getBody()[1][1][i][j].value;
									break;
								case "Unit":
									strUnit = notification.getBody()[1][1][i][j].value;
									break;
								case "State":
									if (notification.getBody()[1][1][i][j].value == "2")
									{
										strState = "<任务>";
									}
									else
									{
										strState = "";
									}
									break;
							}
						}
						
						roleData.roleGoods = {"id":strID, "name":strName, "carry":strCarry, "store":strStore, "unit":strUnit, "state":strState};
					}
					break;
				case "Skill":
					for (i = 0; i < notification.getBody()[1][1].length; i++)
					{						
						for (j = 0; j < notification.getBody()[1][1][i].length; j++)
						{
							switch(notification.getBody()[1][1][i][j].name)
							{
								case "Skill_ID":
									strID = notification.getBody()[1][1][i][j].value;
									break;
								case "Name":
									strName = notification.getBody()[1][1][i][j].value;
									break;
								case "Rank":
									switch (notification.getBody()[1][1][i][j].value)
									{
										case "1":
											strRank = "一级";
											break;
										case "2":
											strRank = "二级";
											break;
										case "3":
											strRank = "三级";
											break;
										case "4":
											strRank = "四级";
											break;
										case "5":
											strRank = "五级";
											break;
										case "6":
											strRank = "六级";
											break;
										case "7":
											strRank = "七级";
											break;
										case "8":
											strRank = "八级";
											break;
										case "9":
											strRank = "九级";
											break;
									}
									break;
								case "Exp":
									strExp = notification.getBody()[1][1][i][j].value;
									break;
								case "State":
									strState = notification.getBody()[1][1][i][j].value;
									break;
							}
						}
						
						roleData.roleSkill = {"id":strID, "name":strName, "rank":strRank, "exp":strExp, "state":strState};
					}
					break;
				case "Item":
					break;
				case "Army":
					break;
				case "Mission":
					for (i = 0; i < notification.getBody()[1][1].length; i++)
					{						
						for (j = 0; j < notification.getBody()[1][1][i].length; j++)
						{
							switch(notification.getBody()[1][1][i][j].name)
							{
								case "Mission_ID":
									strID = notification.getBody()[1][1][i][j].value;
									break;
								case "Name":
									strName = notification.getBody()[1][1][i][j].value;
									break;
								case "Detail":
									strDetail = notification.getBody()[1][1][i][j].value;
									break;
								case "State":
									strState = notification.getBody()[1][1][i][j].value;
									break;
							}
						}
						
						roleData.roleMission = {"id":strID, "name":strName, "detail":strDetail, "state":strState};
					}
					break;
				case "setDetail":
					roleData.roleDetail = {"name":notification.getBody()[1][1].name, "value":notification.getBody()[1][1].value};
					
					switch(notification.getBody()[1][1].name)
					{
						case "Role_ID":
							routeNotification(CommonConstants.MODULE_INVOKE, ["-init", ["roleID", notification.getBody()[1][1].value]], null, "*");
							break;						
						case "ImageID":
							routeNotification(CommonConstants.MODULE_INVOKE, ["-head", notification.getBody()[1][1].value], null, CommonConstants.MODULE_CHARACTER + "/*");
							break;
						case "StaminaNum":
							routeNotification(CommonConstants.MODULE_INVOKE, ["-stamina", notification.getBody()[1][1].value], null, CommonConstants.MODULE_CHARACTER + "/*");
							break;
						case "EnergyNum":
							routeNotification(CommonConstants.MODULE_INVOKE, ["-energy", notification.getBody()[1][1].value], null, CommonConstants.MODULE_CHARACTER + "/*");
							break;
					}
					break;
				case "setGoods":
					if (notification.getBody()[1][1].state == "2")
					{
						strState = "<任务>";
					}
					else
					{
						strState = "";
					}
					roleData.roleGoods = {"id":notification.getBody()[1][1].id, "name":notification.getBody()[1][1].name, "carry":notification.getBody()[1][1].carry, "store":notification.getBody()[1][1].store, "unit":notification.getBody()[1][1].unit, "state":strState};
					break;
				case "setSkill":
					switch (notification.getBody()[1][1].value)
					{
						case "1":
							strRank = "一级";
							break;
						case "2":
							strRank = "二级";
							break;
						case "3":
							strRank = "三级";
							break;
						case "4":
							strRank = "四级";
							break;
						case "5":
							strRank = "五级";
							break;
						case "6":
							strRank = "六级";
							break;
						case "7":
							strRank = "七级";
							break;
						case "8":
							strRank = "八级";
							break;
						case "9":
							strRank = "九级";
							break;
					}
					
					roleData.roleSkill = {"id":notification.getBody()[1][1].id, "name":notification.getBody()[1][1].name, "rank":strRank, "exp":notification.getBody()[1][1].exp, "state":notification.getBody()[1][1].state};
					break;
				case "setItem":
					
					break;
				case "setArmy":
					
					break;
				case "setMission":
					
					break;
				case "roleDetail":
					routeNotification(CommonConstants.MODULE_INVOKE, ["-role", ["roleDetail", roleData.roleDetail]], null, CommonConstants.MODULE_ACTION + "/*");
					break;
				case "roleGoods":	
					routeNotification(CommonConstants.MODULE_INVOKE, ["-role", ["roleGoods", roleData.roleGoods]], null, CommonConstants.MODULE_ACTION + "/*");
					break;
				case "roleSkill":
					routeNotification(CommonConstants.MODULE_INVOKE, ["-role", ["roleSkill", roleData.roleSkill]], null, CommonConstants.MODULE_ACTION + "/*");
					break;
				case "roleItem":
					routeNotification(CommonConstants.MODULE_INVOKE, ["-role", ["roleItem", roleData.roleItem]], null, CommonConstants.MODULE_ACTION + "/*");
					break;
				case "roleArmy":
					routeNotification(CommonConstants.MODULE_INVOKE, ["-role", ["roleArmy", roleData.roleArmy]], null, CommonConstants.MODULE_ACTION + "/*");
					break;
				case "roleMission":
					routeNotification(CommonConstants.MODULE_INVOKE, ["-tool", ["mission", roleData.roleMission]], null, CommonConstants.MODULE_ACTION + "/*");
					break;
			}
		}
		
		//Custom
	}
}